package com.um.jdy.platform.financial.controller;


import com.um.jdy.common.finance.entity.dto.PlatformBillDTO;
import com.um.jdy.common.finance.entity.po.PlatformBill;
import com.um.jdy.platform.financial.entity.dto.BillExportDTO;
import com.um.jdy.platform.financial.entity.dto.BillPageDTO;
import com.um.jdy.platform.financial.entity.vo.PlatformBillItemVO;
import com.um.jdy.platform.financial.manager.PlatformBillManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.ExportParams;
import com.um.springboot.starter.orm.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 控制器：平台流水表
 */
@RestController
@RequestMapping("/api/v1/cms/finance/platform_bill")
@Api(tags = "财务管理", description = "平台流水表")
@ApiPermission("platform_bill")
@TokenRequired
@Validated
public class PlatformBillController extends BaseController<PlatformBillManager> {

    @ApiPermission("add")
    @ApiOperation("新增")
    @PostMapping
    public Response<PlatformBill> add(@Valid @RequestBody PlatformBillDTO dto) {
        return manager.addEntity(dto);
    }

    /**
     * 分页查询平台收银流水
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation("平台流水分页")
    @PostMapping("/bill_page")
    public Response<Page<PlatformBillItemVO>> getBillPage(@RequestBody BillPageDTO params){
        PageParams pageParams = params.toPageParams(
                new String[]{"no","type","event","orderNo","outTradeNo"},
                new String[]{"a.no","a.type","a.event","a.order_no","a.out_trade_no"},
                "a.create_time","beginTime","endTime");
        return manager.getBillPage(pageParams);
    }

    /**
     * 导出平台收银流水
     *
     * @param params
     * @return
     */
    @ApiPermission("export")
    @ApiOperation("平台流水导出")
    @PostMapping("/export_bill_page")
    public Response exportBillPage(@RequestBody BillExportDTO params){
        ExportParams exportParams = params.toExportParams(
                new String[]{"no","type","event","orderNo","outTradeNo"},
                new String[]{"a.no","a.type","a.event","a.order_no","a.out_trade_no"},
                "a.create_time","beginTime","endTime");
        return manager.exportBillPage(exportParams);
    }
}
